package Thread;

import java.util.Scanner;

public class Demo21 {
    private volatile static int flag=0;

    public static void main(String[] args) {
        Thread t1=new Thread(()->{
           while(flag==0){
                try {//不能依赖sleep，会影响到程序的效率
                    Thread.sleep(1);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
           }
           System.out.println("t1线程结束");
        });
        Thread t2=new Thread(()->{
            Scanner sc=new Scanner(System.in);
            System.out.println("请输入flag的值");
            flag=sc.nextInt();
        });
        t1.start();
        t2.start();
    }
}
